package com.bigdata.collector.labels;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.bigdata.collector.model.Page;
import com.bigdata.collector.util.HttpUtils;

public class Collector4Money163 extends AbstractCollector {

	private static Logger logger = Logger.getLogger(Collector4Money163.class);
	private String category;

	public Collector4Money163(String seed) {
		super(seed);

	}

	public Collector4Money163(String seed, String category) {
		this(seed);
		this.category = category;
	}

	public static void main(String[] args) {
		String[] seeds = { "renwu", "gongsi", "zhishi", "shijian" };
		int i = 1;
		for (String seed : seeds) {
			Collector4Money163 ct = new Collector4Money163(
					"http://money.163.com/baike/" + seed, i + "");
			i++;
			ct.run();
		}
		// save("万福生科（湖南）农业开发股份有限公司", 2 + "");
	}

	public static void crawl(String url, String category) {

	}

	@Override
	public void crawler(String url) {
		try {
			Page page = HttpUtils.fetchHttpResponse(url);
			Document doc = Jsoup.parse(new String(page.content, "gb2312"));
			extractTags(doc);
		} catch (Exception e) {
			logger.error(ExceptionUtils.getStackTrace(e));
		}
	}

	@Override
	boolean extractTags(Document doc) {
		Elements es = doc.getElementById("content").getElementsByTag("a");
		for (Element e : es) {
			String label = e.text().trim();
			save2DB(label, category);
		}
		return true;
	}

	@Override
	public void extractURLs(Document doc) {

	}
}
